﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Windows.Forms;

namespace DukeySoundHelper.API
{
    public class DukeyComm
    {
        public static int ChangeUnit = 3;//设置调节单位
        public static bool AutoStart = true;//自动开机启动
        public static string Highkey = "Ctrl";
        public static string Lowkey = "Ctrl";
        public static bool IsMouseLeft = true;
        public static bool IsMouseRight = false;
        public static DataSet ds = new DataSet();
        public static int waitseconds = 4;
        public static string backcolor = "#5EB031";
        public static int WinPopLeft = -1;//浮动框位置左
        public static int WinPopTop = -1;//浮动框位置上
        public static string lang = "english";

        #region 发送邮件
        /// <summary>
        /// 公钥
        /// </summary>
        public static string pubKey = "";

        /// <summary>
        /// 注册码
        /// </summary>
        public static string signKey = "";

        public static void SendSMTPEMail(string strSmtpServer, int iSmtpPort, string strFrom, string strFromPass, string strto, string strSubject, string strBody) //strFrom 要用完整邮件地址格式
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer, iSmtpPort);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
            //Attachment myAttachment = new Attachment("C:\\tradetracker\\InstSummary.xls"); //创建一个附件
            //message.Attachments.Add(myAttachment); //添加附件

            client.Send(message);
        }
        #endregion

        public static Color ToColor(string color)
        {

            int red, green, blue = 0;
            char[] rgb;
            color = color.TrimStart('#');
            color = Regex.Replace(color.ToLower(), "[g-zG-Z]", "");
            switch (color.Length)
            {
                case 3:
                    rgb = color.ToCharArray();
                    red = Convert.ToInt32(rgb[0].ToString() + rgb[0].ToString(), 16);
                    green = Convert.ToInt32(rgb[1].ToString() + rgb[1].ToString(), 16);
                    blue = Convert.ToInt32(rgb[2].ToString() + rgb[2].ToString(), 16);
                    return Color.FromArgb(red, green, blue);
                case 6:
                    rgb = color.ToCharArray();
                    red = Convert.ToInt32(rgb[0].ToString() + rgb[1].ToString(), 16);
                    green = Convert.ToInt32(rgb[2].ToString() + rgb[3].ToString(), 16);
                    blue = Convert.ToInt32(rgb[4].ToString() + rgb[5].ToString(), 16);
                    return Color.FromArgb(red, green, blue);
                default:
                    return Color.FromName(color);

            }
        }
        public static string ColorToHex(Color _color)
        {           
            return "#"+Convert.ToString(Color.FromArgb(_color.R, _color.G, _color.B).ToArgb(), 16).Substring(2);
        }
        public static HotKey.KeyModifiers ConvertToZhuheKey(Keys key)
        {
            HotKey.KeyModifiers keymodi = new HotKey.KeyModifiers();
            switch (key)
            {
                case Keys.Control: keymodi = HotKey.KeyModifiers.Ctrl;
                    break;
                case Keys.Shift: keymodi = HotKey.KeyModifiers.Shift; break;
                case Keys.Alt: keymodi = HotKey.KeyModifiers.Alt; break;

                case Keys.Control | Keys.Alt: keymodi = HotKey.KeyModifiers.Ctrl | HotKey.KeyModifiers.Alt; break;
                case Keys.Control | Keys.Shift: keymodi = HotKey.KeyModifiers.Ctrl | HotKey.KeyModifiers.Shift; break;
                case Keys.Alt | Keys.Shift: keymodi = HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Shift; break;
                case Keys.Control | Keys.Alt | Keys.Shift: keymodi = HotKey.KeyModifiers.Ctrl | HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Shift; break;
                case Keys.None: keymodi = HotKey.KeyModifiers.None; break;
            }
            return keymodi;
        }

    }

    public class MyConfig
    {
        public static MyConfig Instance = new MyConfig();
        #region 鼠标功能
        /// <summary>
        /// 鼠标左键+滚轮向上
        /// </summary>
        public bool IsMouseLeftUp { get; set; }

        /// <summary>
        /// 鼠标左键+滚轮向下
        /// </summary>
        public bool IsMouseLeftDown { get; set; }


        public bool IsMouseRightUp { get; set; }

        public bool IsMouseRightDown { get; set; }

        public bool IsMouseMiddleUp { get; set; }

        public bool IsMouseMiddleDown { get; set; }

        public bool IsMouseLeftRight { get; set; }
        public bool IsMouseRightLeft { get; set; }
        public bool IsMouseRightMiddle { get; set; }

        #endregion
        public int ChangeUnit { get; set; }
        public bool AutoStart { get; set; }
        public string Highkey { get; set; }
        public string Lowkey { get; set; }
        public  bool IsMouseLeft{get;set;}
        public  bool IsMouseRight{get;set;}
        private int waitseconds = 3;

        public int Waitseconds
        {
            get { return waitseconds; }
            set { waitseconds = value; }
        }
        public string BackColor { get; set; }
        public int WinPopLeft { get; set; }
        public int WinPopTop { get; set; }
        public string lang { get; set; }

        private bool canUseHotKeys = true;

        /// <summary>
        /// 是否可以使用热键,默认=true
        /// </summary>
        public bool CanUseHotKeys
        {
            get { return canUseHotKeys; }
            set { canUseHotKeys = value; }
        }
        private bool canUseMouseKeys = true;

        /// <summary>
        /// 是否可以使用鼠标热键,默认=false
        /// </summary>
        public bool CanUseMouseKeys
        {
            get { return canUseMouseKeys; }
            set { canUseMouseKeys = value; }
        }

        private KeyValuePair<Keys, Keys> highkeys = new KeyValuePair<Keys, Keys>(Keys.Control, Keys.Up);

        public KeyValuePair<Keys, Keys> Highkeys
        {
            get { return highkeys; }
            set { highkeys = value; }
        }
        private KeyValuePair<Keys, Keys> lowkeys = new KeyValuePair<Keys, Keys>(Keys.Control, Keys.Down);

        public KeyValuePair<Keys, Keys> Lowkeys
        {
            get { return lowkeys; }
            set { lowkeys = value; }
        }

        private KeyValuePair<Keys, Keys> mutekeys = new KeyValuePair<Keys, Keys>(Keys.Control, Keys.Left);

        /// <summary>
        /// 静音按键设置
        /// </summary>
        public KeyValuePair<Keys, Keys> Mutekeys
        {
            get { return mutekeys; }
            set { mutekeys = value; }
        }
    }

    //public class ChkInfo
    //{
        
    //}
}
